﻿using System.Windows;
using System.Windows.Data;

namespace ShinyWizard
{
    internal static class NotifyDataContextChanged<T>
        where T : FrameworkElement, INotifyDataContextChanged<T>
    {
        public static readonly DependencyProperty ContextProperty = DependencyProperty.Register(
            "Context", 
            typeof(object), 
            typeof(T), 
            new PropertyMetadata(OnContextChanged));

        private static void OnContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var control = (T)sender;
            control.OnDataContextChanged(control, e);
        }

        public static void BindContext(T control)
        {
            control.SetBinding(ContextProperty, new Binding());
        }
    }
}
